home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58606
/
58606.xpi
/
chrome
/
translator.jar
/
content
/
floatingPanel.js
next >
Wrap
Text File
|
2010-02-06
|
3KB
|
145 lines
(function(namespace, $)
{
namespace.FloatingPanel = function(doc)
{
this.doc = doc;
};
namespace.FloatingPanel.prototype = {
initialized: false,
doc: null,
panel: null,
css: {},
visible: false,
init: function()
{
if(this.initialized) return;
// create panel
this.createPanel();
this.initialized = true;
},
uninit: function()
{
this.reset();
this.el.remove();
this.el = null;
this.elMessage = null;
this.css = {};
this.message = '';
this.visible = false;
this.initialized = false;
},
createPanel: function()
{
this.panel = $('<div class="translator-floating-panel"></div>', this.doc);
// style panel
this.panel.css({
background: '#D9C6B6',
border: '2px #784F2B ridge',
bottom: 'auto',
cursor: 'pointer',
display: 'none',
height: 'auto',
left: 0,
margin: 0,
padding: 0,
position: 'fixed',
right: 'auto',
top: 0,
width: 'auto',
zIndex: 9999999999
});
// opacity does not work through jQuery css for some reason
this.panel[0].style.opacity = 0.4;
// add translate button
var $button = $('<div title="Click to translate"></div>', this.doc).appendTo(this.panel);
// style translate button
$button.css({
background: 'url("chrome://translator/skin/icons.png") top left no-repeat',
display: 'block',
height: '16px',
margin: '2px',
width: '16px'
});
// set hover for floating panel
this.panel.hover(
function(e) {
this.panel[0].style.opacity = 1;
}.bind(this),
function(e) {
this.panel[0].style.opacity = 0.4;
}.bind(this)
);
// set click for floating panel
this.panel.click(function(e) {
$(this.doc).trigger('translatorTranslateSelection.translator');
this.hide();
return false;
}.bind(this));
$('body', this.doc).append(this.panel);
},
reloadCss: function()
{
this.panel.css({
bottom: (this.css.x != undefined ? 'auto' : 0),
left: (this.css.x != undefined ? this.css.x : 'auto'),
right: (this.css.y != undefined ? 'auto' : 0),
top: (this.css.y != undefined ? this.css.y : 'auto')
});
},
show: function()
{
if(!this.initialized) {
this.init();
}
if(!this.panel) return;
this.reloadCss();
if(!this.visible) {
this.visible = true;
this.panel.show(250);
}
},
hide: function()
{
if(!this.panel) return;
this.panel.hide(100);
this.visible = false;
},
setPosition: function(x, y)
{
this.css.x = x + 10;
this.css.y = y + 10;
},
resetPosition: function()
{
this.css = {};
}
};
})(com.igorgladkov.translator, translatorJQuery);